#tag Class
Protected Class phonetic
	#tag Method, Flags = &h0
		Sub Constructor()
		  dim i as Integer
		  // Words to be displayed
		  dispWords = Array("Alpha", "Bravo", "Charlie", "Delta", "Echo", _
		  "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", _
		  "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", _
		  "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", _
		  "X-ray", "Yankee", "Zulu", "zero", "one", "two", "tree", _
		  "fower", "fife", "six", "seven", "eight", "niner",  _
		  cstr(EndOfLine) )
		  // Words to be spoken
		  for i = 0 to 35
		    spkWords(i) = dispWords(i)
		  next i
		  // Three words don't pronounce very well on my system
		  spkWords(5) = "FoxTrott"
		  spkWords(10) = "Keelo"
		  spkWords(11) = "Leema"
		  // Pause between words whenr speaking
		  spkWords(36) = ". "
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1
		Protected Function doConvert(s As String, w() As String) As String
		  dim i , maxI as Integer
		  dim c , accum As String
		  dim pos as Integer
		  maxI = len(s)
		  s=Lowercase(s)
		  for i = 1 to maxI
		    c = mid(s,i,1)
		    pos = instr(1,letters,c)
		    if pos > 0 then
		      c = w(pos-1)
		    end if
		    accum = accum + c
		    if c <> cstr(EndOfLine) then
		      accum = accum + " "
		    end if
		  Next i
		  return RTrim(accum)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function getSpeak(s as string) As String
		  return doConvert(s,spkWords())
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function getDisplay(s As String) As String
		  return doConvert(s,dispWords)
		End Function
	#tag EndMethod


	#tag Note, Name = Usage
		dim x as phonetic
		x = new phonetic
		speak x.getSpeak(plainTextField.Text)
		StaticText1.Text= x.getDisplay(plainTextField.Text)
		
	#tag EndNote


	#tag Property, Flags = &h1
		Protected dispWords(37) As String
	#tag EndProperty

	#tag Property, Flags = &h1
		Protected spkWords(37) As string
	#tag EndProperty


	#tag Constant, Name = letters, Type = String, Dynamic = False, Default = \"abcdefghijklmnopqrstuvwxyz0123456789 ", Scope = Protected
	#tag EndConstant


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
